package xiao_jin.fantastic_journey.core.common.item;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SmithingTemplateItem;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.resource.featuretoggle.FeatureFlag;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import xiao_jin.fantastic_journey.util.ModUtil;

import java.util.List;

public class ModSmithingTemplateItem extends SmithingTemplateItem {
    private static final Formatting TITLE_FORMATTING = Formatting.GRAY;
    private static final Formatting DESCRIPTION_FORMATTING = Formatting.BLUE;
    public final Text appliesToText;
    public final Text ingredientsText;
    public final Text titleText;
    public final Text baseSlotDescriptionText;
    public final Text additionsSlotDescriptionText;
    public final List<Identifier> emptyBaseSlotTextures;
    public final List<Identifier> emptyAdditionsSlotTextures;

    private static final Text INGREDIENTS_TEXT = Text.translatable(
            Util.createTranslationKey("item", Identifier.ofVanilla("smithing_template.ingredients"))).formatted(TITLE_FORMATTING);
    private static final Text APPLIES_TO_TEXT = Text.translatable(
            Util.createTranslationKey("item", Identifier.ofVanilla("smithing_template.applies_to"))).formatted(TITLE_FORMATTING);
    private static final Text ANCIENT_FOOD_UPGRADE_APPLIES_TO_TEXT = Text.translatable(
            Util.createTranslationKey("item", ModUtil.getIdOfMod("smithing_template.ancient_food_upgrade.applies_to"))).formatted(DESCRIPTION_FORMATTING);
    private static final Text ANCIENT_FOOD_UPGRADE_INGREDIENTS_TEXT = Text.translatable(
            Util.createTranslationKey("item", ModUtil.getIdOfMod("smithing_template.ancient_food_upgrade.ingredients"))).formatted(DESCRIPTION_FORMATTING);
    private static final Text ANCIENT_FOOD_UPGRADE_BASE_SLOT_DESCRIPTION_TEXT = Text.translatable(
            Util.createTranslationKey("item", ModUtil.getIdOfMod("smithing_template.ancient_food_upgrade.base_slot_description")));
    private static final Text ANCIENT_FOOD_UPGRADE_ADDITIONS_SLOT_DESCRIPTION_TEXT = Text.translatable(
            Util.createTranslationKey("item", ModUtil.getIdOfMod("smithing_template.ancient_food_upgrade.additions_slot_description")));
    private static final Text ANCIENT_FOOD_UPGRADE_TEXT = Text.translatable(Util.createTranslationKey("upgrade", ModUtil.getIdOfMod("ancient_food_upgrade"))).formatted(TITLE_FORMATTING);

    private static List<Identifier> getAncientFoodUpgradeEmptyBaseSlotTextures() {
        return List.of(ModUtil.getIdOfMod("item/empty_armor_slot_food"));
    }

    private static List<Identifier> getAncientFoodUpgradeEmptyAdditionsSlotTextures() {
        return List.of(ModUtil.getIdOfMod("item/empty_slot_warden_heart"));
    }

    /**
     * ModSmithingTemplateItem的构造函数
     *
     * @param appliesToText                适用范围的文本描述
     * @param ingredientsText              材料的文本描述
     * @param titleText                    标题文本
     * @param baseSlotDescriptionText      基础槽的描述文本
     * @param additionsSlotDescriptionText 添加物槽的描述文本
     * @param emptyBaseSlotTextures        空基础槽的纹理列表
     * @param emptyAdditionsSlotTextures   空添加物槽的纹理列表
     * @param requiredFeatures             必需的功能标志
     */
    public ModSmithingTemplateItem(Text appliesToText, Text ingredientsText, Text titleText, Text baseSlotDescriptionText, Text additionsSlotDescriptionText, List<Identifier> emptyBaseSlotTextures, List<Identifier> emptyAdditionsSlotTextures, Text appliesToText1, Text ingredientsText1, Text titleText1, Text baseSlotDescriptionText1, Text additionsSlotDescriptionText1, List<Identifier> emptyBaseSlotTextures1, List<Identifier> emptyAdditionsSlotTextures1, FeatureFlag... requiredFeatures) {
        super(appliesToText, ingredientsText, titleText, baseSlotDescriptionText, additionsSlotDescriptionText, emptyBaseSlotTextures, emptyAdditionsSlotTextures, requiredFeatures);
        this.appliesToText = appliesToText1;
        this.ingredientsText = ingredientsText1;
        this.titleText = titleText1;
        this.baseSlotDescriptionText = baseSlotDescriptionText1;
        this.additionsSlotDescriptionText = additionsSlotDescriptionText1;
        this.emptyBaseSlotTextures = emptyBaseSlotTextures1;
        this.emptyAdditionsSlotTextures = emptyAdditionsSlotTextures1;
    }

    /**
     * 向物品的提示信息中添加额外的文本
     *
     * @param stack   物品堆
     * @param context 提示上下文
     * @param tooltip 提示文本列表
     * @param type    提示类型
     */
    @Override
    public void appendTooltip(ItemStack stack, Item.TooltipContext context, List<Text> tooltip, TooltipType type) {
        super.appendTooltip(stack, context, tooltip, type);
        tooltip.add(this.titleText);
        tooltip.add(ScreenTexts.EMPTY);
        tooltip.add(APPLIES_TO_TEXT);
        tooltip.add(ScreenTexts.space().append(this.appliesToText));
        tooltip.add(INGREDIENTS_TEXT);
        tooltip.add(ScreenTexts.space().append(this.ingredientsText));
    }

    public static SmithingTemplateItem createAncientFoodUpgrade() {
        return new SmithingTemplateItem(
                ANCIENT_FOOD_UPGRADE_APPLIES_TO_TEXT,
                ANCIENT_FOOD_UPGRADE_INGREDIENTS_TEXT,
                ANCIENT_FOOD_UPGRADE_TEXT,
                ANCIENT_FOOD_UPGRADE_BASE_SLOT_DESCRIPTION_TEXT,
                ANCIENT_FOOD_UPGRADE_ADDITIONS_SLOT_DESCRIPTION_TEXT,
                getAncientFoodUpgradeEmptyBaseSlotTextures(),
                getAncientFoodUpgradeEmptyAdditionsSlotTextures()
        );
    }
}
